﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace HRSWeb.Presentation.Login
{
    public class AuthenticationManager
    {
        private static AuthenticationManager _current;
        public static AuthenticationManager Current
        {
            get
            {
                if (_current == null)
                    _current = new AuthenticationManager();
                return _current;

            }
        }

        private AuthenticationManager()
        {

        }

        private HrsServiceProxy.AuthenticationServiceClient _client;
        public HrsServiceProxy.AuthenticationServiceClient Client
        {
            get
            {
                if (_client == null)
                    _client = new HrsServiceProxy.AuthenticationServiceClient();
                return _client;
            }
        }

        public void Logout()
        {
            AuthenticatedUser.Current.Remove();
        }

        public bool Login(string username, string password)
        {
            HrsServiceProxy.AuthenticatedUserDTO _user = null;
            _user = Client.ValidateUser(username, password);
            if (_user != null)
            {
                AuthenticatedUser.Current.User = _user;
            }
            else
            {
                throw new Exception("Hatalı kullanıcı adı veya şifre.");
            }
            return true;
        }

    }
}